<template>
  <div class="rest">
    <div class="common">
      <div class="common-input">
        <el-input
          v-model="commonValue"
          placeholder="用户昵称/手机号码"
          clearable
        ></el-input>
      </div>

      <div class="common-input">
        <el-select v-model="commonUpdateValue" placeholder="请选择" clearable>
          <el-option
            v-for="item in commonUpdateOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>

      <div class="common-input">
        <el-date-picker
          v-model="commonDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
           format="yyyy-MM-dd" value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>

      <div class="common-button" @click="searchHit">搜索</div>
      <div class="common-button" @click="replacementHit">重置</div>
    </div>

    <div class="table" v-loading="loading">
      <el-table
        :data="tableData"
        border
        :header-cell-style="{
          color: '#333333',
          backgroundColor: '#f3f3f3',
        }"
      >
        <el-table-column prop="nickname" label="提现用户" width="200">
        </el-table-column>
        <el-table-column prop="phone" label="提现用户手机号" width="200">
        </el-table-column>

        <el-table-column
          prop="withdrawPrice"
          label="提现金额（元）"
          width="200"
        >
        </el-table-column>
        <el-table-column prop="" label="到账渠道" width="150">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.withdrawType == 0" type="success"
              >微信</el-tag
            >
            <el-tag v-if="scope.row.withdrawType == 1">支付宝</el-tag>
            <el-tag v-if="scope.row.withdrawType == 2" type="warning"></el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="alipayPhone" label="支付宝手机号" width="200">
        </el-table-column>
        <el-table-column prop="alipayName" label="支付宝姓名" width="200">
        </el-table-column>
        <el-table-column prop="bankUserName" label="银行卡姓名" width="200">
        </el-table-column>
        <el-table-column prop="bankNo" label="银行卡卡号" width="200">
        </el-table-column>
        <el-table-column prop="bank" label="银行开户行" width="200">
        </el-table-column>

        <el-table-column prop="createTime" label="申请提现时间" width="250">
        </el-table-column>
        <el-table-column prop="type" label="状态" width="200">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.auditStatus == 0" type="info"
              >待审核</el-tag
            >
            <el-tag v-if="scope.row.auditStatus == 1" type="success"
              >已成功</el-tag
            >
            <el-tag v-if="scope.row.auditStatus == 2" type="error"
              >已拒绝</el-tag
            >
          </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <div class="operation">
              <div
                class="list"
                @click.prevent="disposeHit(scope.row)"
                v-if="scope.row.auditStatus == 0"
              >
                审核
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="tableDataTotal"
          :current-page="page"
        >
        </el-pagination>
      </div>
    </div>

    <!--新增或者编辑-->
    <div class="add">
      <el-dialog
        title="审核页面"
        :visible.sync="addVisible"
        :before-close="addClose"
        width="30%"
      >
        <div class="add-form">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="140px"
            class="demo-ruleForm"
          >
            <el-form-item label="审核状态" prop="status">
              <el-select
                v-model="ruleForm.status"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in addOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="审核备注" prop="text">
              <el-input
                type="textarea"
                :rows="4"
                v-model="ruleForm.text"
                placeholder="请输入合同审批备注"
              ></el-input>
            </el-form-item>

            <el-form-item class="attachment">
              <div class="list" @click="addClose">取消</div>
              <div class="list" @click="addConfirm('ruleForm')">提交</div>
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { restWithdrawList, restWithdrawListPost } from "@/api/rest";

export default {
  data() {
    return {
      commonValue: "",
      commonUpdateOptions: [
        {
          value: "0",
          label: "待审核",
        },
        {
          value: "1",
          label: "已成功",
        },
        {
          value: "2",
          label: "已拒绝",
        },
      ],
      commonUpdateValue: "",
      commonDate: [],
      commonStart: "",
      commonEnd: "",
      //-------------
      page: 1,
      limit: 10,
      tableData: [],
      tableDataTotal: 0,
      loading: false,
      commonObj: {},
      //------------
      addVisible: false,
      addOptions: [
        {
          value: "0",
          label: "待审核",
        },
        {
          value: "1",
          label: "同意",
        },
        {
          value: "2",
          label: "拒绝",
        },
      ],
      ruleForm: {
        text: "",
        status: "0",
      },
      rules: {
        text: [
          { required: true, message: "请输入合同审批备注", trigger: "blur" },
        ],
        status: [
          { required: true, message: "请选择审核状态", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.loading = true;
    this.restFeedbackListMet();
  },
  methods: {
    restFeedbackListMet() {
      let params = {
        withdrawType: "",
        auditStatus: this.commonUpdateValue,
        status: "",
        keyWord: this.commonValue,
        startTime: this.commonStart,
        endTime: this.commonEnd,
        //------
        pageSize: this.limit,
        pageNo: this.page,
      };

      restWithdrawList(params).then((res) => {
        if (res.errorCode == null) {
          res.resultData.userWithdrawList.forEach((item, index) => {
            item.withdrawPrice = Number(item.withdrawPrice / 100);
          });

          this.tableData = res.resultData.userWithdrawList;
          this.tableDataTotal = res.resultData.totalNum;
          this.loading = false;
        }
      });
    },
    timeData(date) {
      return date.toLocaleString("zh-CN", {
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
        // hour: "2-digit",
        // minute: "2-digit",
        // second: "2-digit",
      });
    },
    searchHit() {
      if (this.commonDate.length > 0) {
        this.commonStart = this.timeData(new Date(this.commonDate[0]));
        this.commonEnd = this.timeData(new Date(this.commonDate[1]));
      } else {
        this.commonStart = "";
        this.commonEnd = "";
      }

      this.page = 1;
      this.loading = true;
      this.restFeedbackListMet();
    },
    replacementHit() {
      this.commonDate = [];
      this.commonStart = "";
      this.commonEnd = "";
      this.commonValue = "";

      this.commonUpdateValue = "";

      this.page = 1;
      this.loading = true;
      this.restFeedbackListMet();
    },
    //-------------------------
    disposeHit(item) {
      if (this.$store.state.premissions.infoRouterShow == false) {
        this.$message.error("暂无权限，请联系管理员开通");
        return;
      }
      this.commonObj = item;
      this.ruleForm.status = item.auditStatus
      this.addVisible = true;
    },
    addClose() {
      this.addVisible = false;
    },
    addConfirm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let params = {
            userWithdrawId: this.commonObj.userWithdrawId,
            auditStatus: this.ruleForm.status,
            break: this.ruleForm.text,
          };

          restWithdrawListPost(params).then((res) => {
            if (res.errorCode == null) {
              this.$message.success("审核成功！");
              this.addVisible = false;
              this.loading = true;
              this.restFeedbackListMet();
            }
          });
        } else {
          return false;
        }
      });
    },

    //---------
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      this.restFeedbackListMet();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      this.restFeedbackListMet();
    },
  },
};
</script>

<style lang="less" scoped>
@import url("@/assets/css/official.less");

.rest {
  .common {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    .common-input {
      margin-right: 10px;
      /deep/ .el-input {
        width: 250px;
      }
    }

    .common-input:last-child {
      margin-right: 0;
    }

    .common-button {
      padding: 9px 20px;
      box-sizing: border-box;
      border-radius: 5px;
      background: #2a82e4;
      font-size: 14px;
      color: #fff;
      margin-left: 20px;
      cursor: pointer;
    }

    .common-button:last-child {
      background: #999999;
    }
  }

  .table {
    cursor: pointer;

    .operation {
      display: flex;
      align-items: center;
      color: #2a82e4;

      .list {
        margin-right: 20px;
        cursor: pointer;
      }
    }

    .imgs {
      width: 50px;
      height: 50px;
    }
  }

  .add,
  .uploading {
    /deep/ .el-dialog__header {
      font-size: 16px;
      text-align: center;
    }

    /deep/ .el-dialog__body {
      padding-bottom: 10px;
    }

    .add-form {
      /deep/ .el-select {
        width: 100%;
      }

      .img {
        width: 70px;
        height: 70px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid #ccc;
        border-radius: 5px;

        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }

      .attachment {
        margin-top: 50px;
        /deep/ .el-form-item {
          margin-bottom: 0;
        }

        /deep/ .el-form-item__content {
          margin-left: 0 !important;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        .list {
          background: #3da8f5;
          color: #fff;
          font-size: 16px;
          margin-right: 50px;
          border-radius: 5px;
          width: 100px;
          height: 35px;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
        }

        .list:first-child {
          background: #808080;
        }

        .list:last-child {
          margin-right: 0;
        }
      }
    }
  }
}
</style>